/*例如删除课程表的一条记录时，把这个课程在选课表中的记录也删除*/
/*创建触发器的执行函数*/
create or replace function delete_course()
returns trigger as $$
begin
	delete from keystudents where cno = old.cno;
	return old;
end;
$$
language plpgsql;

/*创建触发器*/
create trigger delete_course_trigger
after delete on courses
for each row execute procedure delete_course();


/*例如删除教师表的一条记录时，把这个教师在课程表的记录也删除*/
/*创建触发器的执行函数*/
create or replace function delete_teacher()
returns trigger as $$
begin
	delete from courses where tno = old.tno;
	return old;
end;
$$
language plpgsql;

/*创建触发器*/
create trigger delete_teacher_trigger
after delete on teachers
for each row execute procedure delete_teacher();